import { AppModel } from '../../../../model/AppModel'
import { createGPIOMenu } from '../BlockPackage'

export default {

    category: Blockly.Categories.bepart ,
    
    color: [
        Blockly.Colours.bepart.primary,
        Blockly.Colours.bepart.secondary,
        Blockly.Colours.bepart.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,

    init(model: AppModel) {
        this.appendDummyInput()
            .appendField("设置模式")
            .appendField(createGPIOMenu(model), 'pin')
            .appendField(new Blockly.FieldDropdown(async () => {
                return [
                    ["模拟输入(ADC)", 'analog'] ,
                    ["数字输入(悬空)", 'input'] ,
                    ["数字输入(上拉)", 'input-pullup'] ,
                    ["数字输入(下拉)", 'input-pulldown'] ,
                    ["数字输出", 'output'] ,
                ]
            }), 'mode')
    } ,

    coder: {
        JavaScript(block: any, coder: any) {
            let pin = block.getFieldValue('pin')
            let mode = block.getFieldValue('mode')
            return `${coder.indentString()}pinMode(${pin}, "${mode}")\n`
        }
    }
}
